package com.company.huisuo.biz.adapter

import android.app.Activity
import android.view.LayoutInflater
import android.view.ViewGroup
import com.company.huisuo.R
import com.company.huisuo.base.BaseSingleAdapter
import com.company.huisuo.biz.activity.ArtistInfoActivity
import com.company.huisuo.biz.bean.ArtistBean
import com.company.huisuo.databinding.ItemArtistListRankBinding
import com.company.huisuo.ext.loadCircleImg
import com.company.huisuo.ext.loadImg

/**
 * 艺人榜单列表适配器
 */
class ArtistRankListAdapter : BaseSingleAdapter<ArtistBean, ItemArtistListRankBinding>() {

    override val initViewBinding: (LayoutInflater, ViewGroup, Boolean) -> ItemArtistListRankBinding
        get() = ItemArtistListRankBinding::inflate

    override fun convert(
        holder: SingleViewHolder<ItemArtistListRankBinding>, position: Int, item: ArtistBean?
    ) {
        item?.let {
            holder.binding.apply {
                tvRank.text = (position + 4).toString()
                ivAvatar.loadCircleImg(it.avatar)
                tvName.text = it.name
                tvPopularity.text = "${it.popular}"
                tvAge.text = "${it.age}岁"
                tvJob.text = it.job
                val drawable = if (position % 2 == 0) {
                    R.drawable.bg_artist_rank_age_1
                } else {
                    R.drawable.bg_artisr_rank_age_2
                }
                tvAge.setBackgroundResource(drawable)
                ivAvatar.setOnClickListener {
                    ArtistInfoActivity.start(context as Activity, item)
                }
            }
        }
    }
}
